package com.zpark.controller;

import com.zpark.service.ex.ZZSearchBasicException;
import com.zpark.service.ex.ZZSearchSearchTermsIsEmptyException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author xiaoyu
 * @version 1.0 2022/12/8
 */

@ControllerAdvice

public class ZZSearchGlobalExceptionHandlerController {
    @ExceptionHandler(ZZSearchBasicException.class)
    public ModelAndView handlerServiceException(Throwable e) {
        ModelAndView mv = new ModelAndView();
        if(e instanceof ZZSearchSearchTermsIsEmptyException) { // 说明搜索词为空
            mv.setViewName("any");
            mv.addObject("msg", e.getMessage());
        }
        return mv;
    }
}
